package com.example.excel.Controller;

// UserController.java
import cn.hutool.json.JSONUtil;
import com.example.excel.Service.UserService;
import com.example.excel.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private  UserService userService;


    @GetMapping("/info")
    public String getUser() {
        User byId = userService.getById(1l);
        System.out.println(JSONUtil.toJsonStr(byId));
        System.out.println(JSONUtil.toJsonStr(userService.getById(4l)));
        byId.setAge(55);
        System.out.println(userService.updateById(byId));
        User user = new User();
        user.setId("5454");
        System.out.println(userService.save(user));
        return JSONUtil.toJsonStr(byId);
    }

    @PostMapping
    public boolean createUser(@RequestBody User user) {
        return userService.save(user);
    }

    @PutMapping
    public boolean updateUser(@RequestBody User user) {
        return userService.updateById(user);
    }

    @DeleteMapping("/{id}")
    public boolean deleteUser(@PathVariable Long id) {
        return userService.removeById(id);
    }
}